﻿<UserControl x:Class="DropDownButtonTest.Views.DemoView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 

             xmlns:ctrls="clr-namespace:DropDownButtonLib.Controls;assembly=DropDownButtonLib"
             xmlns:bindLocal="clr-namespace:DropDownButtonTest.Views"
             xmlns:themes="clr-namespace:DropDownButtonLib.Core.Themes;assembly=DropDownButtonLib"
             
             mc:Ignorable="d"   
             d:DesignHeight="800" d:DesignWidth="500">
      <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition  Height="*"/>
    </Grid.RowDefinitions>

    <Grid Grid.Row="0" Margin="9,3">
      <TextBlock HorizontalAlignment="Center" FontSize="22" TextWrapping="Wrap">
        Click the DropDown and SplitButton below to see how these work.<LineBreak/>
        <LineBreak/>
        Insert a <TextBlock FontWeight="Bold">ResourceDictionary</TextBlock> reference in <TextBlock FontWeight="Bold">App.xaml</TextBlock> to activate a supported theme:<LineBreak/><LineBreak/>
        <TextBlock FontWeight="Bold">DropDownButtonLib</TextBlock>/Themes/Generic.xaml and<LineBreak/>
        <TextBlock FontWeight="Bold">DropDownButtonLib</TextBlock>/Themes/Aero2.NormalColor.xaml<LineBreak/><LineBreak/>
        Note: The Generic.xaml theme does not need explicit activation<LineBreak/>
        because WPF loads it by default when nothings else was defined.<LineBreak/>
      </TextBlock>
    </Grid>

    <Grid Grid.Row="1" HorizontalAlignment="Left">
      <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition Width="*" />
      </Grid.ColumnDefinitions>

      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>

      <StackPanel Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Left">
        <Label Content="One Item, Drop Down Button" HorizontalAlignment="Left"/>
        <ctrls:DropDownButton Margin="0,0,3,0"
                              MinWidth="150"
                              IsEnabled="{Binding DropDownButtonTest.IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                              Content="{Binding DropDownButtonTest.ButtonLabel,FallbackValue='Binding Failed'}"                              
                              Command="{Binding DropDownButtonTest.DropDownButtonClickCommand}"
                              CommandParameter="{Binding DropDownButtonTest.SliderValue}"
                              IsOpen="{Binding DropDownButtonTest.IsOpen, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                              HorizontalAlignment="Left"
                            >
          <ctrls:DropDownButton.DropDownContent>
            <StackPanel>
              <StackPanel Orientation="Horizontal" Margin="3">
                <Slider Value="{Binding DropDownButtonTest.SliderValue}" Maximum="100" Minimum="0"  MinWidth="200"/>
                <TextBlock Text="{Binding DropDownButtonTest.SliderValue, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
              </StackPanel>
              <StackPanel Orientation="Horizontal"> 
                <Button  Margin="10" Content="OK"
                       Command="{Binding DropDownButtonTest.ItemButtonClickCommand}"
                       CommandParameter="{Binding DropDownButtonTest.SliderValue}"/>
                <Button  Margin="10" Content="Cancel"
                       Command="{Binding DropDownButtonTest.ItemCancelCommand}"/>
              </StackPanel>
            </StackPanel>
          </ctrls:DropDownButton.DropDownContent>
        </ctrls:DropDownButton>
        <CheckBox Content="IsEnabled"
                  IsChecked="{Binding DropDownButtonTest.IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                  HorizontalAlignment="Left"
                  />
      </StackPanel>
      <TextBox Grid.Column="1" Grid.Row="0"
               Text="{Binding DropDownButtonTest.Status, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
               VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
      />
      <Separator Grid.ColumnSpan="2" Grid.Row="1" />

      <StackPanel Grid.Column="0" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Left">
        <Label Content="Multiple Items, Drop Down Button" HorizontalAlignment="Left" />
        <ctrls:DropDownItemsButton Margin="0,0,3,0"
                                   MinWidth="150"
                                   IsEnabled="{Binding DropDownItemsButtonTest.IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                   Content="{Binding DropDownItemsButtonTest.ButtonLabel,FallbackValue='Binding Failed'}"
                                   ItemsSource="{Binding DropDownItemsButtonTest.DropDownItems}"
                                   Command="{Binding DropDownItemsButtonTest.DropDownButtonClickCommand}"
                                   IsOpen="{Binding DropDownItemsButtonTest.IsOpen, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                   HorizontalAlignment="Left"
                                   DropDownMaxHeight="300"
                                  >
          <ctrls:DropDownItemsButton.Resources>
            <!-- Use a proxy to bind items to root object of this collection -->
            <bindLocal:BindingProxy  x:Key="DropDownItemsButtonProxy" Data="{Binding DropDownItemsButtonTest}" />
          </ctrls:DropDownItemsButton.Resources>
          <ctrls:DropDownItemsButton.ItemTemplate>
            <DataTemplate>
              <Grid>
                <TextBlock Margin="3,1">
                  <TextBlock.Style>
                    <Style TargetType="{x:Type TextBlock}">
                      <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                          <Setter Property="Cursor" Value="Arrow"/>
                          <Setter Property="Background" Value="{DynamicResource {x:Static themes:ResourceKeys.DropDownList_MouseOverBackgroundKey}}" />
                        </Trigger>
                      </Style.Triggers>
                    </Style>
                  </TextBlock.Style>
                  <!-- A hyperlink in disguise without change of mouse pointer or underline indicator  -->
                  <Hyperlink Command="{Binding Path=Data.ItemButtonClickCommand, Source={StaticResource DropDownItemsButtonProxy}}"
                             CommandParameter="{Binding}"><!-- Send this item for processing to the bound command -->
                        <Hyperlink.Style>
                          <Style TargetType="{x:Type Hyperlink}">
                            <Style.Triggers>
                              <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Foreground" Value="Black" />
                                <Setter Property="Cursor"     Value="Arrow"/>
                              </Trigger>
                              <Trigger Property="IsEnabled"   Value="false">
                                <Setter Property="Cursor" Value="Arrow"/>
                                <Setter Property="Foreground" Value="Black"/>
                              </Trigger>
                              <Trigger Property="IsEnabled" Value="true">
                                <Setter Property="Cursor" Value="Arrow"/>
                              </Trigger>
                            </Style.Triggers>
                            <Setter Property="TextBlock.TextDecorations" Value="{x:Null}" />
                            <Setter Property="Foreground" Value="Black" />
                          </Style>
                        </Hyperlink.Style>
                    <TextBlock Text="{Binding Path=DisplayItemName}" />
                  </Hyperlink>                        
                </TextBlock>
              </Grid>
            </DataTemplate>
          </ctrls:DropDownItemsButton.ItemTemplate>
        </ctrls:DropDownItemsButton>
        <CheckBox Content="IsEnabled"
                  IsChecked="{Binding DropDownItemsButtonTest.IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                  HorizontalAlignment="Left" />
      </StackPanel>
      <TextBox Grid.Column="1" Grid.Row="2"
               IsReadOnly="True"
               Text="{Binding DropDownItemsButtonTest.Status, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
               VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
      />
      <Separator Grid.ColumnSpan="2" Grid.Row="3" />

      <StackPanel Grid.Column="0" Grid.Row="4" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0">
        <Label Content="One Items, Split Button" HorizontalAlignment="Left" Margin="3,0" />
        <ctrls:SplitButton Margin="0,0,3,0"
                           MinWidth="150"
                           IsEnabled="{Binding SplitButtonTest.IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                           Content="{Binding SplitButtonTest.SelectedItem,FallbackValue='Binding Failed'}"                              
                           Command="{Binding SplitButtonTest.DropDownButtonClickCommand}"
                           CommandParameter="{Binding SplitButtonTest.SliderValue}"
                           IsOpen="{Binding SplitButtonTest.IsOpen, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                           HorizontalAlignment="Left"
                          >
          <ctrls:SplitButton.DropDownContent>
            <StackPanel>
              <StackPanel Orientation="Horizontal" Margin="3">
                <Slider Value="{Binding SplitButtonTest.SliderValue}" Maximum="100" Minimum="0"  MinWidth="200"/>
                <TextBlock Text="{Binding SplitButtonTest.SliderValue, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
              </StackPanel>
              <StackPanel Orientation="Horizontal">
                <Button  Margin="10" Content="OK"
                         Command="{Binding SplitButtonTest.ItemButtonClickCommand}"
                         CommandParameter="{Binding SplitButtonTest.SliderValue}"/>
                <Button  Margin="10" Content="Cancel"
                         Command="{Binding SplitButtonTest.ItemCancelCommand}"/>
              </StackPanel>
            </StackPanel>
          </ctrls:SplitButton.DropDownContent>
        </ctrls:SplitButton>
        <CheckBox Content="IsEnabled"
                  IsChecked="{Binding SplitButtonTest.IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                  HorizontalAlignment="Left"
                  />
      </StackPanel>
      <TextBox Grid.Column="1" Grid.Row="4"
               Text="{Binding SplitButtonTest.Status, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
               VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
      />
      <Separator Grid.ColumnSpan="2" Grid.Row="5" />

      <StackPanel Grid.Column="0" Grid.Row="6" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0">
        <Label Content="Multiple Items, Split Button" HorizontalAlignment="Left" Margin="3,0" />
        <ctrls:SplitItemsButton Margin="0,0,3,0"
                                MinWidth="150" MinHeight="23"
                                IsEnabled="{Binding SplitItemsButtonTest.IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                Content="{Binding SplitItemsButtonTest.SelectedItem.DisplayItemName,FallbackValue='Binding Failed'}"
                                ItemsSource="{Binding SplitItemsButtonTest.DropDownItems}"
                                Command="{Binding SplitItemsButtonTest.DropDownButtonClickCommand}"
                                CommandParameter="{Binding SplitItemsButtonTest.SelectedItem}"
                                IsOpen="{Binding SplitItemsButtonTest.IsOpen, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                DropDownMaxHeight="300"
                                HorizontalAlignment="Left"
                              >
          <ctrls:DropDownItemsButton.Resources>
            <!-- Use a proxy to bind items to root object of this collection -->
            <bindLocal:BindingProxy  x:Key="DropDownItemsButtonProxy" Data="{Binding SplitItemsButtonTest}" />
          </ctrls:DropDownItemsButton.Resources>
          <ctrls:DropDownItemsButton.ItemTemplate>
            <DataTemplate>
              <Grid>
                <TextBlock Margin="3,1">
                  <TextBlock.Style>
                    <Style TargetType="{x:Type TextBlock}">
                      <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                          <Setter Property="Cursor" Value="Arrow"/>
                          <Setter Property="Background" Value="{DynamicResource {x:Static themes:ResourceKeys.DropDownList_MouseOverBackgroundKey}}" />
                        </Trigger>
                      </Style.Triggers>
                    </Style>
                  </TextBlock.Style>
                  <!-- A hyperlink in disguise without change of mouse pointer or underline indicator  -->
                  <Hyperlink Command="{Binding Path=Data.ItemButtonClickCommand, Source={StaticResource DropDownItemsButtonProxy}}"
                             CommandParameter="{Binding}"><!-- Send this item for processing to the bound command -->
                        <Hyperlink.Style>
                          <Style TargetType="{x:Type Hyperlink}">
                            <Style.Triggers>
                              <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Foreground" Value="Black" />
                                <Setter Property="Cursor"     Value="Arrow"/>
                              </Trigger>
                              <Trigger Property="IsEnabled"   Value="false">
                                <Setter Property="Cursor" Value="Arrow"/>
                                <Setter Property="Foreground" Value="Black"/>
                              </Trigger>
                              <Trigger Property="IsEnabled" Value="true">
                                <Setter Property="Cursor" Value="Arrow"/>
                              </Trigger>
                            </Style.Triggers>
                            <Setter Property="TextBlock.TextDecorations" Value="{x:Null}" />
                            <Setter Property="Foreground" Value="Black" />
                          </Style>
                        </Hyperlink.Style>
                    <TextBlock Text="{Binding Path=DisplayItemName}" />
                  </Hyperlink>                        
                </TextBlock>
              </Grid>
            </DataTemplate>
          </ctrls:DropDownItemsButton.ItemTemplate>
        </ctrls:SplitItemsButton>
        <CheckBox Content="IsEnabled"
                  IsChecked="{Binding SplitItemsButtonTest.IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                  HorizontalAlignment="Left"
                  />
      </StackPanel>
      <TextBox Grid.Column="1" Grid.Row="6"
               Text="{Binding SplitItemsButtonTest.Status, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
               VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
      />
      <Separator Grid.ColumnSpan="2" Grid.Row="7" />
    </Grid>
  </Grid>
</UserControl>
